package com.yiren.manager.service.impl.elder;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.Favorites;
import com.yiren.entity.YrBedRetain;
import com.yiren.entity.YrCgIndiServiceSendOrder;
import com.yiren.entity.YrCgSendOrder;
import com.yiren.entity.YrElderBeHospital;
import com.yiren.manager.repository.department.YrCgIndiServiceSendOrderRepository;
import com.yiren.manager.repository.department.YrCgSendOrderRepository;
import com.yiren.manager.repository.elder.YrBedRetainRepository;
import com.yiren.manager.repository.elder.YrElderBeHospitalRepository;
import com.yiren.manager.repository.elder.YrElderWalletRepository;
import com.yiren.manager.repository.elder.YrWalletReturnRepository;
import com.yiren.manager.service.iface.elder.YrBedRetainService;

@Service
public class YrBedRetainServiceImpl extends GenericServiceImpl<YrBedRetain, String> implements YrBedRetainService{

	@Autowired
	private YrCgIndiServiceSendOrderRepository cgIndiServiceSendOrderRepository;
	
	@Autowired
	private YrCgSendOrderRepository cgSendOrderRepository;
	
	@Autowired
	private YrElderBeHospitalRepository elderBeHospitalRepository;

	@Autowired
	private YrElderWalletRepository elderWalletRepository;
	
	@Autowired
	private YrWalletReturnRepository walletReturnRepository;
	
	@Autowired
	public YrBedRetainServiceImpl(YrBedRetainRepository repository) {
		super(repository);
	}

	@Transactional
	public void addByFavorites(Favorites entitys) throws MyException {
		YrBedRetain retain = entitys.getFavorite(YrBedRetain.class);
		YrCgIndiServiceSendOrder cgIndiServiceSendOrder = entitys.getFavorite(YrCgIndiServiceSendOrder.class);
		YrCgSendOrder cgSendOrder = entitys.getFavorite(YrCgSendOrder.class);
		YrElderBeHospital elderBeHospital = entitys.getFavorite(YrElderBeHospital.class);
		
		this.repository.save(retain);
		if(cgIndiServiceSendOrder!=null){
			cgIndiServiceSendOrderRepository.save(cgIndiServiceSendOrder);
		}
		if(cgSendOrder!=null){
			cgSendOrderRepository.save(cgSendOrder);
		}
		if(elderBeHospital!=null){
			elderBeHospitalRepository.save(elderBeHospital);
		}
	}

	@Transactional
	public void modifyByFavorites(Favorites entitys) throws MyException {
		// TODO Auto-generated method stub
		
	}

	@Transactional
	public void finish(Favorites entitys) throws MyException {
		YrElderBeHospital elderBeHospital = entitys.getFavorite(YrElderBeHospital.class);
		YrBedRetain bedRetain = entitys.getFavorite(YrBedRetain.class);
//		YrWalletReturn walletReturn = entitys.getFavorite(YrWalletReturn.class);
//		YrElderWallet elderWallet = entitys.getFavorite(YrElderWallet.class);
		//		YrUserVipCardRecord userVipCardRecord = entitys.getFavorite(YrUserVipCardRecord.class);
		
//		userVipCardRecordRepository.save(userVipCardRecord);
		elderBeHospitalRepository.save(elderBeHospital);
		this.repository.save(bedRetain);
//		walletReturnRepository.save(walletReturn);
//		elderWalletRepository.save(elderWallet);
	}

}
